package com.zh.note.huawei.twohundred.荒岛求生;

import java.util.Arrays;
import java.util.Stack;

/**
 * @Author: zhanghuan
 * @date: 2023/8/24 19:14
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // String input = sc.nextLine();
        String input = "5 10 8 -8 -5";
        String[] s = input.split(" ");
        int[] nums = Arrays.stream(s).mapToInt(Integer::parseInt).toArray();
        Stack<Integer> left = new Stack<>();//存负数绝对值
        Stack<Integer> right = new Stack<>();//存正数

        for (int num : nums) {
            if (num > 0) {
                right.push(num);
            } else {
                left.push(Math.abs(num));
            }
        }
        while (!left.isEmpty() && !right.isEmpty()) {
            if (left.peek() > right.peek()) {
                left.push(left.pop() - right.pop());
            } else if (left.peek() < right.peek()) {
                right.push(right.pop() - left.pop());
            } else {
                left.pop();
                right.pop();
            }
        }
        System.out.println(left.size() + right.size());


    }
}
